#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

void merge(int* nums1, int m, int* nums2, int n);

int main()
{
    int nums1[] = { 1, 2, 3, 0, 0, 0 };
    int m = 3;
    int nums2[] = { 2, 5, 6 };
    int n = 3;
    int i = 0;
    merge(nums1, m, nums2, n);
    for (i = 0; i < m + n; i++)
    {
        printf("%d ", nums1[i]);
    }
    return 0;
}

void merge(int* nums1, int m, int* nums2, int n) 
{
    int end1 = m - 1;
    int end2 = n - 1;
    int tail = m + n - 1;
    while (end2 >= 0 && end1 >= 0)
    {
        if (*(nums2 + end2) > *(nums1 + end1))
        {
            *(nums1 + tail) = *(nums2 + end2);
            tail--;
            end2--;
        }
        else
        {
            *(nums1 + tail) = *(nums1 + end1);
            tail--;
            end1--;
        }
    }
    while (end2 >= 0)
    {
        *(nums1 + tail) = *(nums2 + end2);
        tail--;
        end2--;
    }
}